<template>
  <view class="login-page w-full mt-20 relative text-center">
    <wd-img width="180rpx" height="180rpx" round :src="userInfoLogo" />
    <text class="block">AidMaster图灵</text>
    <view class="mt-10 w-[80%] my-0 mx-auto">
      <button
        v-if="isShowPhoneButton"
        open-type="getPhoneNumber"
        class="phone-button"
        @getphonenumber="onGetPhoneNumber"
      >
        绑定您的手机号
      </button>
      <wd-button v-else block :loading="isLoading" :disabled="isLoading" @tap="onLogin">
        一键登录/注册
      </wd-button>
    </view>
    <view class="text-3 mt-12">
      登录即代表同意<text class="text-[#c13432]" @tap="gotoServer">《服务条款》</text>
    </view>
  </view>
</template>
<script lang="ts" setup>
import UseLogin from "./hooks/useLogin";
import userInfoLogo from "@/static/logo.png";
import { useUserStore } from "@/store/index";

const { onGetPhoneNumber, wxLogin, isLoading, isShowPhoneButton } = new UseLogin();
const { getInfo } = useUserStore();
const routerParam = ref<string>("/pages/index/index");

// 微信登录
const onLogin = async () => {
  // 微信登录
  await wxLogin();
  // 获取信息
  await getInfo();

  uni.switchTab({
    url: routerParam.value,
  });
};

// 服务条款
const gotoServer = () => {
  uni.showToast({
    icon: "none",
    title: "Todo List",
  });
};

onLoad((option) => {
  console.log(option);
  if (option && option?.redirect) {
    routerParam.value = option?.redirect;
  }
});
</script>
<style lang="scss" scoped>
.phone-button {
  font-size: 28rpx;
  color: #ffffff;
  background-color: #4d80f0;
  border-radius: 40rpx;
}
</style>
